var MyTable={
    searchForm:"searchForm",
    searchUrl:"/wxgroup/list",
	tableId:"lgTable",
	table:null,
	prefix:"/wxgroup/"
};

$(function() {
    var defaultColunms = MyTable.initColumn();
    var table = new BSTable(MyTable.tableId, MyTable.searchUrl,defaultColunms);
    table.setPaginationType('client');
	MyTable.table = table.init(0);
});
function reLoad() {
	MyTable.table.refresh(null);
}

MyTable.initColumn = function () {
    var columns =  [
		{checkbox : true},
		{field : 'id',title : '序号'},
		{field : 'name',title : '标签'},
		{
			title : '操作',
			field : 'id',
			align : 'center',
			formatter : function(value, row, index) {
			var e = '<a class="btn btn-primary  btn-sm ' + editBtn + '" href="#" title="编辑"  mce_href="#" onclick="edit(\''
				+ row.id
				+ '\',\''
				+ row.name
				+ '\')"><i class="fa fa-edit"></i></a> ';
			
			var d = '<a class="btn btn-warning btn-sm ' + editBtn + '" href="#" title="删除"  mce_href="#" onclick="deleteRow(\''
			+ row.id
			+ '\')"><i class="fa fa-remove"></i></a> ';
			return e + d;
			}
		} ];
    return columns;
};

function add(){
	layer.open({
		type : 2,
		title : '创建标签',
		maxmin : true,
		shadeClose : false, // 点击遮罩关闭层
		area : [ '800px', '420px' ],
		content : MyTable.prefix+'/add'
	});
}


function edit(gid,gname){
	layer.open({
		type : 2,
		title : '修改标签',
		maxmin : true,
		shadeClose : false, // 点击遮罩关闭层
		area : [ '800px', '420px' ],
		content : MyTable.prefix+'/edit?gid='+gid+'&gname='+gname
	});
}



function deleteRow(gid){
    var config={
			url : MyTable.prefix+"/deleteRow/"+gid,
			sureDo:true,
			msg:"确定要删除吗？"
	}
	EasyAjax.post(config,function(r){
		layer.msg(r.msg);
		if (r.code == 0){
			reLoad();
		} 
	});
}

function delRows(){
	var rows=checkSelect();
	if(!rows)
	return;
    var config={
			url : MyTable.prefix+"/deleteRows",
			data: {"ids" : rows},
			sureDo:true,
			msg:"确定删除记录？"
	}
	EasyAjax.post(config,function(r){
		layer.msg(r.msg);
		if (r.code == 0){
			reLoad();
		} 
	});
}

function checkSelect(){
	var rows = $('#'+MyTable.tableId).bootstrapTable('getSelections'); // 返回所有选择的行，当没有选择的记录时，返回一个空数组
	if (rows.length == 0) {
		layer.msg("请选择要删除的数据");
		return null;
	}else{
		var ids = new Array();
		$.each(rows, function(i, row) {
			ids[i] = row.id;
		});
		return ids;
	}
}

